package com.hundsun.yr.universal.p2p.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.Utils.HeaderMap;
import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.common.IdcardUtils;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.RegularUtils;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSEditText;
import com.hundsun.yr.universal.p2p.bean.MineInvestProtocolBean;
import com.hundsun.yr.universal.p2p.bean.UpdatePayPwdBeen;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.bean.enums.OssidEnum;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.idcardscan.CardInfo;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.presenter.impl.InitializePresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.utils.Logs;
import com.hundsun.yr.universal.p2p.view.base.InitializeView;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;


/**
 * Created by xx on 2017/4/27.
 * 开户界面
 */
public class OpenAccountBankActivity extends BaseActivity implements InitializeView, View.OnClickListener, HSDialog.HSDialogOnItemClickListener, RadioGroup.OnCheckedChangeListener {
    /**
     * 确认按钮
     **/
    private HSButton btn_sure = null;
    /**
     * 取消按钮
     **/
//    private HSButton btn_come_back = null;
    /**
     * 获取验证码
     **/
//    private ValidateButton btn_vcode = null;
    /**
     * 实名输入框
     **/
    private HSEditText et_name = null;
    /**
     * 身份证号输入框
     **/
    private HSEditText et_certno = null;
    /**
     * 银行卡号
     **/
    private HSEditText et_bankcard = null;
    /**
     * 银行预留手机号
     **/
    private HSEditText et_mobile = null;
    /**
     * 短信验证码
     **/
//    private HSEditText et_vcode = null;
    /**
     * 开户银行
     **/
//    private TextView tv_openaccount = null;
    /**
     * 实名
     **/
    private String userName = null;
    /**
     * 身份证号
     **/
    private String certNo = null;
    /**
     * 请求接口
     **/
    private RequestPresenter mPresenter = null;
    /**
     * 用户输入的手机号
     **/
    private String phone;

    /**
     * 银行卡号
     */
    private String bankID;

    /**
     * 验证码
     */
    private String vcode;

    /**
     * 协议按钮
     */
    private CheckBox ck_agree;

    /**
     * 中网国投用户开户协议
     */
    private TextView tv_zwgt_open_account_protocol;

    /**
     * 支持哪些银行
     */
    private TextView tv_support_bank;

    /**
     * zwgt时间
     */
    private String zwgt_data;

    /**
     * 前往设置交易密码
     **/
    private HSDialog dialog = null;
    private String title;

    /**
     * 身份证扫描
     */
//    private ImageView iv_idcard_scan = null;

    /**
     * 银行卡扫描
     */
//    private ImageView iv_bank_card_scan = null;

    /**
     * 出借，借款人组合
     */
    private RadioGroup rg_lender_or_borrower = null;

    /**
     * 出借人
     */
    private RadioButton rb_lender = null;

    /**
     * 借款人
     */
    private RadioButton rb_borrower = null;
    /**
     * 担保人
     */
    private RadioButton rb_guarantee = null;
    private String identity;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_open_account_bank;
    }

    @Override
    protected void initViewsAndEvents() {
        setToolbarTitle(R.string.certification);
        et_name = findView(R.id.et_name);
        et_certno = findView(R.id.et_certno);
        et_bankcard = findView(R.id.et_bankcard);
        et_mobile = findView(R.id.et_moble);
//        et_vcode = findView(R.id.et_vcode);

//        btn_vcode = findView(R.id.btn_vcode);
        btn_sure = findView(R.id.btn_sure);
//        tv_openaccount = findView(R.id.tv_openaccount);
//        btn_come_back = findView(R.id.btn_come_back);
        ck_agree = findView(R.id.ck_agree);
        rg_lender_or_borrower = findView(R.id.rg_lender_or_borrower);
        rb_lender = findView(R.id.rb_lender);
        rb_borrower = findView(R.id.rb_borrower);
        rb_guarantee = findView(R.id.rb_guarantee);
//        iv_idcard_scan = findView(R.id.iv_idcard_scan);
//        iv_idcard_scan.setOnClickListener(this);
//
//        iv_bank_card_scan = findView(R.id.iv_bank_card_scan);
//        iv_bank_card_scan.setOnClickListener(this);

        ck_agree.setChecked(false);
        tv_zwgt_open_account_protocol = findView(R.id.tv_zwgt_open_account_protocol);
        tv_support_bank = findView(R.id.tv_support_bank);
        tv_support_bank.setOnClickListener(this);
        tv_zwgt_open_account_protocol.setOnClickListener(this);
        btn_sure.setOnClickListener(this);
        rg_lender_or_borrower.setOnCheckedChangeListener(this);
//        btn_vcode.setOnClickListener(this);
//        btn_come_back.setOnClickListener(this);

/*        et_name.setText(sharedPreferences.getShareProf(Config.REALNAME));
        et_certno.setText(sharedPreferences.getShareProf(Config.CERT_NO));*/
        String account_bank = getString(R.string.account_bank);
        String container = getResources().getString(R.string.account_opening, account_bank);
//        tv_openaccount.setText(SpannableStringBuilderUtils.colorSpan(container, account_bank, getResources().getColor(R.color.primary_cl_6)));
        mPresenter = new InitializePresenterImpl(mContext, this);

        if (sharedPreferences.getShareProf(UserInfo.MOBILE) != null && !sharedPreferences.getShareProf(UserInfo.MOBILE).isEmpty()) {
            et_mobile.setText(sharedPreferences.getShareProf(UserInfo.MOBILE));
        }

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected void onEveComming(EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    /**
     * 网络请求成功的回调，开户成功
     *
     * @param task_name 任务名称
     * @param data      返回数据
     * @param <T>
     */
    @Override
    public <T> void initializeViews(String task_name, T data) {
        //拿到开户信息，将用户开户情况进行存储
        switch (task_name) {
            case TaskConstants.TASK_OPENBANKACCOUNTPAGE://实名开户
                //开户成功并且存储开户信息
                MineInvestProtocolBean openAccountBeen = (MineInvestProtocolBean) data;

                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder1 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        TaskConstants.TASK_ACTRST, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap1 = new HeaderMap();
                headerMap1.setMap(hearder1);
                Bundle bundle1 = new Bundle();
                bundle1.putString(BaseWebActivity.BUNDLE_KEY_URL, openAccountBeen.html);
                bundle1.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap1);
//                bundle1.putSerializable(BaseWebActivity.BUNDLE_KEY_TITLE, zwgt_data);
                bundle1.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
                bundle1.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebOpenAccountActivity.class, bundle1);

                //存储开户信息
//                if (!openAccountBeen.depository_bank_no.isEmpty()) {
//                    sharedPreferences.putShareProf(UserInfo.JIANGXI_BANKCARD, openAccountBeen.depository_bank_no);
//                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
//                } else {
//                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
//                }
//
//                //保存用户银行卡手机号
//                if (openAccountBeen.depository_bank_mobile != null && !openAccountBeen.depository_bank_mobile.isEmpty()){
//                    sharedPreferences.putShareProf(UserInfo.BANKMOBILE,openAccountBeen.depository_bank_mobile);
//                } else {
//                    sharedPreferences.putShareProf(UserInfo.BANKMOBILE,"");
//                }
//
//                //保存用户年龄
//                if (openAccountBeen.old != null && !openAccountBeen.old.isEmpty()) {
//                    sharedPreferences.putShareProf(UserInfo.OLD, openAccountBeen.old);
//                } else {
//                    sharedPreferences.putShareProf(UserInfo.OLD, "");
//                }

//                /**
//                 * 成功了就关闭上一个页面
//                 */
//                if (BaseAppManager.getInstance().getActivity(LoginActivity.class) != null){
//                    BaseAppManager.getInstance().getActivity(LoginActivity.class).finish();
//                }
//
//                //刷新用户信息
//                EventBus.getDefault().post(new EventCenter(Constants.EVENT_REFRESH_DATA));
//                //专门通知开户成功
//                EventBus.getDefault().post(new EventCenter(Extras.OPEN_ACCOUNT_SUCCESS));
//
//                //直接前往设置交易密码
////                dialog = new HSDialog(getString(R.string.tips), getString(R.string.tips_nopaypwd),
////                        getString(R.string.cancel), getString(R.string.tips_go_set), mContext, this).setCancelable(false);
////                dialog.show();
//                zwgt_data = BaseRequestTool2.getFormatedDateString();
//                JSONObject map1 = new JSONObject();
//
//                try {
//                    map1.put("vcode", "");
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//                JSONObject jsonParams = CommTool.getJSONParams(map1, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
//                mPresenter.loadingData(TaskConstants.TASK_SETBANKPWD, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, Constants.EVENT_DATA,
//                        jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, sharedPreferences
//                                .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

                break;

            case TaskConstants.TASK_SETBANKPWD:
                if (data == null) {
                    return;
                }

                UpdatePayPwdBeen mUpdatePayPwdBeen = (UpdatePayPwdBeen) data;

                //现在做另外一种操作
                String postData = null;
                try {
                    postData = "accountId=" + URLEncoder.encode(mUpdatePayPwdBeen.data.accountId.toString(), "utf-8") + "&acqRes=" + URLEncoder.encode(mUpdatePayPwdBeen.data.acqRes.toString(), "utf-8") +
                            "&bankCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.bankCode.toString(), "utf-8") + "&channel=" + URLEncoder.encode(mUpdatePayPwdBeen.data.channel.toString(), "utf-8") +
                            "&idNo=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idNo.toString(), "utf-8") + "&idType=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idType.toString(), "utf-8") + "&instCode=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.instCode.toString(), "utf-8") + "&lastSrvAuthCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.lastSrvAuthCode == null ? "" : mUpdatePayPwdBeen.data.lastSrvAuthCode.toString(), "utf-8") +
                            "&mobile=" + URLEncoder.encode(mUpdatePayPwdBeen.data.mobile.toString(), "utf-8") + "&name=" + URLEncoder.encode(mUpdatePayPwdBeen.data.name.toString(), "utf-8") + "&notifyUrl=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.notifyUrl.toString(), "utf-8") + "&retUrl=" + URLEncoder.encode(mUpdatePayPwdBeen.data.retUrl.toString(), "utf-8") + "&seqNo=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.seqNo.toString(), "utf-8") + "&sign=" + URLEncoder.encode(mUpdatePayPwdBeen.data.sign.toString(), "utf-8") + "&smsCode=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.smsCode == null ? "" : mUpdatePayPwdBeen.data.smsCode.toString(), "utf-8") + "&txCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txCode.toString(), "utf-8") +
                            "&txDate=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txDate.toString(), "utf-8") + "&txTime=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txTime.toString(), "utf-8") + "&version=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.version.toString(), "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }

                Bundle bundle = new Bundle();
                bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.set_paywd));
                bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mUpdatePayPwdBeen.url);
                bundle.putString(BaseWebActivity.BUNDLE_KEY_PARAMS, postData);
                bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.POSTDATA.getIntValue());
                bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGoThenKill(WebSetPasswordActivity.class, bundle);

                break;
        }
//        finish();
    }


    /**
     * 网络请求失败的回调，开户失败
     *
     * @param task_name 任务名称
     * @param data
     * @param <T>
     */
    @Override
    public <T> void initializeError(String task_name, T data) {
        showToast(getString(R.string.open_account_fail));
        finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_sure:
                //确认信息，并且将开户需求提交网络
                check();
                break;
/*            case R.id.btn_come_back:
                //取消，关闭开户界面
                finish();
                break;*/
//            case R.id.btn_vcode:
//                //发送验证码短信
//                phone = et_mobile.getText().toString().replace(" ", "");
//                sendVcode(phone);
//                break;

            case R.id.tv_zwgt_open_account_protocol://中网国投用户开户协议
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap mHeader = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.h5_protocol) + TaskConstants.TASK_ACTOPENPROT,
                        "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                HeaderMap headerMap = new HeaderMap();
                headerMap.setMap(mHeader);

                Bundle bundle = new Bundle();
                bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, OssidEnum.OPEN_ACCTOUNT_PROTOCOL.getOssLabel());
                bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mContext.getString(R.string.root_h5_url_test) + getString(R.string.h5_protocol) + TaskConstants.TASK_ACTOPENPROT);
                bundle.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
//                bundle.putString(WebProtocolActivity.PROTOCOL_CODE, EnumProtocol.findCode(EnumProtocol.REGIST_PROTOCOL));
                bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebProtocolActivity.class, bundle);
                break;

            case R.id.tv_support_bank://支持哪些银行
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap mHeader2 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.h5_index) + TaskConstants.TASK_BANKCARDLIST,
                        "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                HeaderMap headerMap2 = new HeaderMap();
                headerMap2.setMap(mHeader2);

                Bundle bundle2 = new Bundle();
                bundle2.putString(BaseWebActivity.BUNDLE_KEY_URL, mContext.getString(R.string.root_h5_url_test) + getString(R.string.h5_index) + TaskConstants.TASK_BANKCARDLIST);
                bundle2.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap2);
                bundle2.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.bankcard));
                bundle2.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle2.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle2);
                break;

//            case R.id.iv_idcard_scan:
//                readyGoForResult(ScanCardActivity_q.class,123);
//                break;
//
//            case R.id.iv_bank_card_scan:
//                readyGoForResult(ScanCamera.class,456);
//                break;
        }
    }

    /**
     * 点击发送验证码
     */
    private void sendVcode(String phone) {
        String zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();

        //检查是否输入手机号
        if (TextUtils.isEmpty(phone)) {
            showToast(R.string.input_bind_mobile);
            return;
        }

        //检查手机号格式
        if (!RegularUtils.isPhoneNum(phone)) {
            showToast(R.string.input_format_mobile);
            return;
        }

        try {
            Logs.e("phone" + phone);
            map.put("srvtxcode", "accountOpenPlus");
            map.put("phone", phone);
//            map.put("channel","0");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
        mPresenter.loadingData(TaskConstants.TASK_SMS_APPLY, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_pub_test) + TaskConstants.TASK_SMS_APPLY, Constants.EVENT_DATA,
                jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_pub_test) + TaskConstants.TASK_SMS_APPLY, sharedPreferences
                        .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
    }

    /**
     * 输入框校验，并且发送网络请求
     */
    private void check() {
        //名字
        userName = et_name.getText().toString();
        //身份证
        certNo = et_certno.getText().toString();
        //号码
        phone = et_mobile.getText().toString().replace(" ", "");
        //银行卡号
        bankID = et_bankcard.getText().toString().replace(" ", "");
        //验证码
//        vcode = et_vcode.getText().toString();

        if (TextUtils.isEmpty(userName)) {
            showToast(R.string.name_emptycheck);
            return;
        }

        if (TextUtils.isEmpty(certNo)) {
            showToast(R.string.cert_emptycheck);
            return;
        }

        if (!IdcardUtils.validateCard(certNo)) {
//			showToast(certNo);
            showToast(R.string.cert_rightcheck);
            return;
        }

        //检查是否输入手机号
        if (TextUtils.isEmpty(phone)) {
            showToast(R.string.input_bind_mobile);
            return;
        }

        //检查手机号格式
        if (!RegularUtils.isPhoneNum(phone)) {
            showToast(R.string.input_format_mobile);
            return;
        }

//        //验证码信息验证
//        if (TextUtils.isEmpty(vcode)) {
//            showToast(getString(R.string.input_mobile_code));
//            return;
//        }
        //验证借款人身份
        if (!rb_lender.isChecked() && !rb_borrower.isChecked() && !rb_guarantee.isChecked()) {
            showToast(R.string.choice_identity);
            return;
        }

        /*//银行卡信息验证
        if (TextUtils.isEmpty(bankID)) {
            showToast(R.string.input_bind_card);
            return;
        } else if (bankID.length() < 14) {
            showToast(R.string.can_user_bankno);
            return;
        }*/

        //名字验证


        //验证ck_agree是否勾选
        if (ck_agree.isChecked() == false) {
            showToast(getString(R.string.tips_agree_protocol, OssidEnum.OPEN_ACCTOUNT_PROTOCOL.getOssLabel()));
            return;
        }

        // TODO: 2017/5/18 存储用户信息
        //存储身份信息
        sharedPreferences.putShareProf(Config.REALNAME, userName);
        sharedPreferences.putShareProf(Config.CERT_NO, certNo);

        String zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        try {
            map.put("name", userName);
            // map.put("bankcard", bankID);
            map.put("phone", phone);
            //   map.put("vcode", vcode);
            map.put("idcard", certNo);
            map.put("identity", identity);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);

        mPresenter.loadingData(TaskConstants.TASK_OPENBANKACCOUNTPAGE, getString(R.string.root_url_test) + getString(R.string.api_user_test) + TaskConstants.TASK_OPENBANKACCOUNTPAGE, Constants.EVENT_DATA,
                jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_user_test) + TaskConstants.TASK_OPENBANKACCOUNTPAGE, sharedPreferences.getShareProf(UserInfo.USER_NO),
                        sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
    }

    @Override
    public void onItemClick(Object o, int position) {
//        if ((HSDialog) o == dialog) {
//            if (position != -1) {
//                zwgt_data = BaseRequestTool2.getFormatedDateString();
//                JSONObject map1 = new JSONObject();
//
//                try {
//                    map1.put("vcode", "");
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//                JSONObject jsonParams = CommTool.getJSONParams(map1, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
//                mPresenter.loadingData(TaskConstants.TASK_SETBANKPWD, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, Constants.EVENT_DATA,
//                        jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, sharedPreferences
//                                .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
//            } else {
//                //关闭开户页面
//                finish();
//            }
//        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 123:
                if (data == null) {
                    return;
                }
                CardInfo info = (CardInfo) data.getSerializableExtra("card");
                et_certno.setText(info.getNum());

                break;

            case 456:
                if (data == null) {
                    return;
                }
                char[] StringR = data.getCharArrayExtra("StringR");
//                showToast(String.valueOf(StringR).trim());
                et_bankcard.setText(String.valueOf(StringR).trim());

                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("OpenAccountBankActivity");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("OpenAccountBankActivity");
        MobclickAgent.onPause(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
        switch (checkedId) {
            case R.id.rb_lender:
                //出借人
                identity = "1";
                break;
            case R.id.rb_borrower:
                //借款人
                identity = "2";
                break;
            case R.id.rb_guarantee:
                identity = "3";
        }
    }
}
